using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using hedefgrup.reports.renault.date;
using System.Globalization;
using hedefgrup.graphicsLibrary;
using System.Drawing;

public partial class forms_common_graph : reportPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.initialize();
        base.ensureUserIsLoggedIn();

        CultureInfo english = CultureInfo.GetCultureInfo("en-US");

        string mapName = base.getString("g_n");
        string subjectName = base.getString("g_s");
        reportMonth[] months = reportMonth.getMonthsInInterval(base.getReportStartMonth(), base.getReportEndMonth());
        string[] xAxisLabels = new string[months.Length];

        for (int i = 0; i < months.Length; i++)
        {
            xAxisLabels[i] = months[i].getMonthName();
        }

        string[] valuesAsText = base.getString("g_v").Split(',');

        float[] values = new float[valuesAsText.Length];

        float minValue = float.MaxValue;
        float maxValue = float.MinValue;
        
        for (int i = 0; i < values.Length; i++)
        {
            values[i] = Convert.ToSingle(valuesAsText[i], english);
            if (Single.IsNaN(values[i])) values[i] = 0;
            minValue = Math.Min(minValue, values[i]);
            maxValue = Math.Max(maxValue, values[i]);
        }

        minValue = minValue - (minValue % 10);
        maxValue = maxValue + (maxValue % 10 == 0 ? 0 : (10 - maxValue % 10));

        graphic graph = new questionReportGraphic();
        
        graph.mapNameLines = new string[] { mapName, subjectName };
        graph.yValues = values;
        graph.xLabels = xAxisLabels;
        graph.yInterval = 10;
        graph.yMaximumValue = Convert.ToInt32(maxValue);
        graph.yMinimumValue = Convert.ToInt32(minValue);

        graph.mapNameFont = new Font("tahoma", 10F, FontStyle.Bold);
        graph.yAxisFont = new Font("tahoma", 8F);
        graph.xLabelFont = new Font("tahoma", 6.5F);

        Response.ContentType = "image/gif";
        graph.WriteImage(Response.OutputStream);

    }
}
